//
//  NFSRadioNextViewController.m
//  NeedForSpeed
//
//  Created by 王国强 on 15/10/21.
//  Copyright © 2015年 Avenger. All rights reserved.
//

#import "NFSRadioNextViewController.h"

#import "BaseHeader.h"

#import "NFSNextModel.h"

#import "NFSRadioTableViewCell.h"


@interface NFSRadioNextViewController ()<UITableViewDataSource,UITableViewDelegate>


@property(nonatomic,strong)NSMutableArray *radioArray;
@property(nonatomic,strong)UIImageView *radioView;
@property(nonatomic,strong)UITableView *radiosView ;
@end

@implementation NFSRadioNextViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self.view setBackgroundColor:[UIColor whiteColor]];
    [self createView];
    [self createTableView];
    [self getData];
    
    
    
    
}
- (void)getData
{
    _radioArray = [[NSMutableArray alloc]init];
    [AFNETWORK getdataWithString:self.adrress block:^(id block) {
        for (NSDictionary *dic in [[block objectForKey:@"result"]objectForKey:@"list"]) {
            NFSNextModel *model = [[NFSNextModel alloc]initWithDictionary:dic];
            [_radioArray addObject:model];
        }
        [_radiosView reloadData];
    }];
}
- (void)createView
{
    _radioView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0,SCREEN_WIDTH , SCREEN_HEIGHT / 4)];
    [_radioView setImage:[UIImage imageNamed:@"RadioNext.jpg"]];
    [_radioView setBackgroundColor:[UIColor blackColor]];
    [self.view addSubview:_radioView];
    
    UIImageView *radioNameImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, SCREEN_HEIGHT / 16, SCREEN_HEIGHT / 8, SCREEN_HEIGHT/8)];
    NSURL *url = [NSURL URLWithString:self.imageurl];
    [radioNameImage sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"hoder.jpg"]];
    [radioNameImage.layer setBorderColor:[UIColor blackColor].CGColor];
    [radioNameImage.layer setBorderWidth:1.];
    [radioNameImage.layer setCornerRadius:SCREEN_HEIGHT/ 16];
    radioNameImage.layer.masksToBounds = YES;
    [_radioView addSubview:radioNameImage];
    
    UILabel *nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_HEIGHT /8, SCREEN_HEIGHT /16, SCREEN_HEIGHT /8, 30)];
    [nameLabel setText:self.radioName];
    [nameLabel setTextColor:[UIColor whiteColor]];
    [_radioView addSubview:nameLabel];
    
    UILabel *album_descritionLabel = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_HEIGHT /8, SCREEN_HEIGHT / 16 + 10, SCREEN_WIDTH -SCREEN_HEIGHT / 8, _radioView.frame.size.height - SCREEN_HEIGHT / 16)];
    [album_descritionLabel setNumberOfLines:0];
    [album_descritionLabel setText:self.album_descrition];
    [album_descritionLabel setFont:[UIFont systemFontOfSize:14.]];
    [album_descritionLabel setTextColor:[UIColor whiteColor]];
    [_radioView addSubview:album_descritionLabel];
}
- (void)createTableView
{
    _radiosView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStylePlain];
    _radiosView.delegate =self;
    _radiosView.dataSource =self;
    
    [_radiosView setTableHeaderView:_radioView];
    [_radiosView setBounces:NO];
    [self.view addSubview:_radiosView];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _radioArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellId = @"cell";
    NFSRadioTableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:cellId];
    if (!cell) {
        cell = [[NFSRadioTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
    }
    NFSNextModel *model = [_radioArray objectAtIndex:indexPath.row];
    [cell getModel:model];
    return cell;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 70;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NFSNextModel *model = [_radioArray objectAtIndex:indexPath.row];
    [self.playRadioDelegate playRadio:model.program_fileurl];
    [self.navigationController popViewControllerAnimated:YES];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
